/** @description 必要配置 */
import App from './App'
import ajax from './utils/request.js' //导入外部js
/** @description 非vue3配置 */
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false;
Vue.config.ignoredElements = [
	'wx-open-launch-weapp',
]
App.mpType = 'app';
try {
	function isPromise(obj) {
		return (
			!!obj &&
			(typeof obj === "object" || typeof obj === "function") &&
			typeof obj.then === "function"
		);
	}

	// 统一 vue2 API Promise 化返回格式与 vue3 保持一致
	uni.addInterceptor({
		returnValue(res) {
			if (!isPromise(res)) {
				return res;
			}
			return new Promise((resolve, reject) => {
				res.then((res) => {
					if (res[0]) {
						reject(res[0]);
					} else {
						resolve(res[1]);
					}
				});
			});
		},
	});
} catch (error) { }

const app = new Vue({
	...App
})
app.$mount()
// #endif
/** @description vue3配置 */
// #ifdef VUE3
import store from './store'
import { createSSRApp } from 'vue'
import Vuex from "vuex"; //状态管理机
export function createApp() {
	const app = createSSRApp(App)
	app.use(store)
	app.config.globalProperties.$ajax = ajax; ///在这里直接定义到全局里，用this.$ajax调用
	app.config.globalProperties.$onLaunched = new Promise(resolve => {
		app.config.globalProperties.$isResolve = resolve
	})
	return { app }
}
// #endif